﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibKetoan;

namespace Ketoan
{

	public class frmRight : System.Windows.Forms.Form
	{
		private AccessData d;
		private System.Windows.Forms.ImageList imgList;
		private System.Windows.Forms.TextBox txtUserId;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.TextBox txtRight;
		private DataSet ds=new DataSet();
		private DataSet dsxml=new DataSet();
		private int i_userid;
		private string s_userid,strRight = "",m_id_copy="";
		private DataSet adsRight = new DataSet();
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.Panel panel3;
		private System.Windows.Forms.Panel panel4;
		private System.Windows.Forms.Panel panel5;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Splitter splitter1;
		private System.Windows.Forms.Panel panel6;
		private System.Windows.Forms.Button butAll;
		private System.Windows.Forms.Button butKethuc;
		private System.Windows.Forms.Button butHuy;
		private System.Windows.Forms.Button butSua;
		private System.Windows.Forms.Button butThem;
		private System.Windows.Forms.Button butLuu;
		private System.Windows.Forms.Panel panel7;
		private System.Windows.Forms.Panel panel8;
		private System.Windows.Forms.TreeView treeView1;
		private System.Windows.Forms.TextBox txtNodeTextSearch;
		private System.Windows.Forms.Label butPastets;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label butCopyts;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ContextMenu contextMenu1;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private System.Windows.Forms.ContextMenu contextMenu2;
		private System.Windows.Forms.MenuItem menuItem8;
		private System.Windows.Forms.MenuItem menuItem9;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.MenuItem menuItem4;
		private System.Windows.Forms.MenuItem menuItem10;
		private System.Windows.Forms.MenuItem menuItem11;
		private System.Windows.Forms.MenuItem menuItem12;
		private System.Windows.Forms.MenuItem menuItem13;
		private System.Windows.Forms.MenuItem menuItem14;
		private System.Windows.Forms.TextBox txtTimUser;
		private DataSet ads_Menu = new DataSet();
		public frmRight(AccessData acc,int userid)
		{
			InitializeComponent();
			d=acc;i_userid=userid;
		}
		public frmRight(AccessData acc,int userid,TreeNode tn)
		{
			InitializeComponent();
			d=acc;i_userid=userid;
			treeView1.Nodes.Add(tn);
		}
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmRight));
            this.imgList = new System.Windows.Forms.ImageList(this.components);
            this.txtUserId = new System.Windows.Forms.TextBox();
            this.txtRight = new System.Windows.Forms.TextBox();
            this.panel1 = new System.Windows.Forms.Panel();
            this.panel2 = new System.Windows.Forms.Panel();
            this.panel3 = new System.Windows.Forms.Panel();
            this.panel4 = new System.Windows.Forms.Panel();
            this.dataGrid1 = new System.Windows.Forms.DataGrid();
            this.contextMenu1 = new System.Windows.Forms.ContextMenu();
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.menuItem2 = new System.Windows.Forms.MenuItem();
            this.panel5 = new System.Windows.Forms.Panel();
            this.txtTimUser = new System.Windows.Forms.TextBox();
            this.splitter1 = new System.Windows.Forms.Splitter();
            this.panel6 = new System.Windows.Forms.Panel();
            this.butAll = new System.Windows.Forms.Button();
            this.butKethuc = new System.Windows.Forms.Button();
            this.butHuy = new System.Windows.Forms.Button();
            this.butSua = new System.Windows.Forms.Button();
            this.butThem = new System.Windows.Forms.Button();
            this.butLuu = new System.Windows.Forms.Button();
            this.panel7 = new System.Windows.Forms.Panel();
            this.treeView1 = new System.Windows.Forms.TreeView();
            this.contextMenu2 = new System.Windows.Forms.ContextMenu();
            this.menuItem8 = new System.Windows.Forms.MenuItem();
            this.menuItem9 = new System.Windows.Forms.MenuItem();
            this.menuItem3 = new System.Windows.Forms.MenuItem();
            this.menuItem4 = new System.Windows.Forms.MenuItem();
            this.menuItem10 = new System.Windows.Forms.MenuItem();
            this.menuItem11 = new System.Windows.Forms.MenuItem();
            this.menuItem12 = new System.Windows.Forms.MenuItem();
            this.menuItem13 = new System.Windows.Forms.MenuItem();
            this.menuItem14 = new System.Windows.Forms.MenuItem();
            this.panel8 = new System.Windows.Forms.Panel();
            this.txtNodeTextSearch = new System.Windows.Forms.TextBox();
            this.butPastets = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.butCopyts = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.panel4.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
            this.panel5.SuspendLayout();
            this.panel6.SuspendLayout();
            this.panel7.SuspendLayout();
            this.panel8.SuspendLayout();
            this.SuspendLayout();
            // 
            // imgList
            // 
            this.imgList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgList.ImageStream")));
            this.imgList.TransparentColor = System.Drawing.Color.Transparent;
            this.imgList.Images.SetKeyName(0, "");
            this.imgList.Images.SetKeyName(1, "");
            this.imgList.Images.SetKeyName(2, "");
            // 
            // txtUserId
            // 
            this.txtUserId.BackColor = System.Drawing.SystemColors.HighlightText;
            this.txtUserId.Enabled = false;
            this.txtUserId.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtUserId.Location = new System.Drawing.Point(650, 250);
            this.txtUserId.Name = "txtUserId";
            this.txtUserId.Size = new System.Drawing.Size(190, 23);
            this.txtUserId.TabIndex = 8;
            // 
            // txtRight
            // 
            this.txtRight.BackColor = System.Drawing.SystemColors.HighlightText;
            this.txtRight.Enabled = false;
            this.txtRight.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtRight.Location = new System.Drawing.Point(635, 320);
            this.txtRight.Name = "txtRight";
            this.txtRight.Size = new System.Drawing.Size(205, 23);
            this.txtRight.TabIndex = 13;
            // 
            // panel1
            // 
            this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
            this.panel1.Location = new System.Drawing.Point(0, 2);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(2, 568);
            this.panel1.TabIndex = 18;
            // 
            // panel2
            // 
            this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.panel2.Location = new System.Drawing.Point(0, 570);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(794, 2);
            this.panel2.TabIndex = 18;
            // 
            // panel3
            // 
            this.panel3.Dock = System.Windows.Forms.DockStyle.Top;
            this.panel3.Location = new System.Drawing.Point(0, 0);
            this.panel3.Name = "panel3";
            this.panel3.Size = new System.Drawing.Size(794, 2);
            this.panel3.TabIndex = 18;
            // 
            // panel4
            // 
            this.panel4.Controls.Add(this.dataGrid1);
            this.panel4.Controls.Add(this.panel5);
            this.panel4.Dock = System.Windows.Forms.DockStyle.Left;
            this.panel4.Location = new System.Drawing.Point(2, 2);
            this.panel4.Name = "panel4";
            this.panel4.Size = new System.Drawing.Size(313, 568);
            this.panel4.TabIndex = 19;
            // 
            // dataGrid1
            // 
            this.dataGrid1.AlternatingBackColor = System.Drawing.SystemColors.Info;
            this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.Info;
            this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.Control;
            this.dataGrid1.CaptionForeColor = System.Drawing.SystemColors.Highlight;
            this.dataGrid1.CaptionVisible = false;
            this.dataGrid1.ColumnHeadersVisible = false;
            this.dataGrid1.ContextMenu = this.contextMenu1;
            this.dataGrid1.DataMember = "";
            this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.dataGrid1.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
            this.dataGrid1.Location = new System.Drawing.Point(0, 22);
            this.dataGrid1.Name = "dataGrid1";
            this.dataGrid1.ReadOnly = true;
            this.dataGrid1.Size = new System.Drawing.Size(313, 546);
            this.dataGrid1.TabIndex = 1;
            this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
            // 
            // contextMenu1
            // 
            this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem1,
            this.menuItem2});
            // 
            // menuItem1
            // 
            this.menuItem1.Index = 0;
            this.menuItem1.Text = "Copy quyền";
            this.menuItem1.Click += new System.EventHandler(this.butCopyts_Click);
            // 
            // menuItem2
            // 
            this.menuItem2.Enabled = false;
            this.menuItem2.Index = 1;
            this.menuItem2.Text = "Paste quyền";
            this.menuItem2.Click += new System.EventHandler(this.butPastets_Click);
            // 
            // panel5
            // 
            this.panel5.Controls.Add(this.txtTimUser);
            this.panel5.Dock = System.Windows.Forms.DockStyle.Top;
            this.panel5.Location = new System.Drawing.Point(0, 0);
            this.panel5.Name = "panel5";
            this.panel5.Size = new System.Drawing.Size(313, 22);
            this.panel5.TabIndex = 0;
            // 
            // txtTimUser
            // 
            this.txtTimUser.Dock = System.Windows.Forms.DockStyle.Fill;
            this.txtTimUser.Location = new System.Drawing.Point(0, 0);
            this.txtTimUser.Name = "txtTimUser";
            this.txtTimUser.Size = new System.Drawing.Size(313, 20);
            this.txtTimUser.TabIndex = 0;
            this.txtTimUser.Text = "Tìm kiếm";
            this.txtTimUser.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtTimUser.TextChanged += new System.EventHandler(this.tim_TextChanged);
            this.txtTimUser.Enter += new System.EventHandler(this.tim_Enter);
            // 
            // splitter1
            // 
            this.splitter1.Location = new System.Drawing.Point(315, 2);
            this.splitter1.Name = "splitter1";
            this.splitter1.Size = new System.Drawing.Size(3, 568);
            this.splitter1.TabIndex = 20;
            this.splitter1.TabStop = false;
            // 
            // panel6
            // 
            this.panel6.Controls.Add(this.butAll);
            this.panel6.Controls.Add(this.butKethuc);
            this.panel6.Controls.Add(this.butHuy);
            this.panel6.Controls.Add(this.butSua);
            this.panel6.Controls.Add(this.butThem);
            this.panel6.Controls.Add(this.butLuu);
            this.panel6.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.panel6.Location = new System.Drawing.Point(318, 540);
            this.panel6.Name = "panel6";
            this.panel6.Size = new System.Drawing.Size(476, 30);
            this.panel6.TabIndex = 21;
            // 
            // butAll
            // 
            this.butAll.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butAll.Image = ((System.Drawing.Image)(resources.GetObject("butAll.Image")));
            this.butAll.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butAll.Location = new System.Drawing.Point(212, 3);
            this.butAll.Name = "butAll";
            this.butAll.Size = new System.Drawing.Size(70, 25);
            this.butAll.TabIndex = 11;
            this.butAll.Text = "Chọn cả";
            this.butAll.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butAll.Click += new System.EventHandler(this.butAll_Click);
            // 
            // butKethuc
            // 
            this.butKethuc.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.butKethuc.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butKethuc.ForeColor = System.Drawing.SystemColors.WindowText;
            this.butKethuc.Image = ((System.Drawing.Image)(resources.GetObject("butKethuc.Image")));
            this.butKethuc.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butKethuc.Location = new System.Drawing.Point(348, 3);
            this.butKethuc.Name = "butKethuc";
            this.butKethuc.Size = new System.Drawing.Size(68, 25);
            this.butKethuc.TabIndex = 13;
            this.butKethuc.Text = "&Kết thúc";
            this.butKethuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butKethuc.Click += new System.EventHandler(this.butKethuc_Click);
            // 
            // butHuy
            // 
            this.butHuy.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butHuy.ForeColor = System.Drawing.SystemColors.WindowText;
            this.butHuy.Image = ((System.Drawing.Image)(resources.GetObject("butHuy.Image")));
            this.butHuy.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butHuy.Location = new System.Drawing.Point(149, 3);
            this.butHuy.Name = "butHuy";
            this.butHuy.Size = new System.Drawing.Size(60, 25);
            this.butHuy.TabIndex = 10;
            this.butHuy.Text = "      &Hủy";
            this.butHuy.Click += new System.EventHandler(this.butHuy_Click);
            // 
            // butSua
            // 
            this.butSua.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butSua.ForeColor = System.Drawing.SystemColors.WindowText;
            this.butSua.Image = ((System.Drawing.Image)(resources.GetObject("butSua.Image")));
            this.butSua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butSua.Location = new System.Drawing.Point(285, 3);
            this.butSua.Name = "butSua";
            this.butSua.Size = new System.Drawing.Size(60, 25);
            this.butSua.TabIndex = 12;
            this.butSua.Text = "     &Sửa";
            this.butSua.Click += new System.EventHandler(this.butSua_Click);
            // 
            // butThem
            // 
            this.butThem.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butThem.ForeColor = System.Drawing.SystemColors.WindowText;
            this.butThem.Image = ((System.Drawing.Image)(resources.GetObject("butThem.Image")));
            this.butThem.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butThem.Location = new System.Drawing.Point(23, 3);
            this.butThem.Name = "butThem";
            this.butThem.Size = new System.Drawing.Size(60, 25);
            this.butThem.TabIndex = 8;
            this.butThem.Text = "&Thêm";
            this.butThem.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butThem.Click += new System.EventHandler(this.butThem_Click);
            // 
            // butLuu
            // 
            this.butLuu.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.butLuu.ForeColor = System.Drawing.SystemColors.WindowText;
            this.butLuu.Image = ((System.Drawing.Image)(resources.GetObject("butLuu.Image")));
            this.butLuu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butLuu.Location = new System.Drawing.Point(86, 3);
            this.butLuu.Name = "butLuu";
            this.butLuu.Size = new System.Drawing.Size(60, 25);
            this.butLuu.TabIndex = 9;
            this.butLuu.Text = "    &Lưu";
            this.butLuu.Click += new System.EventHandler(this.butLuu_Click);
            // 
            // panel7
            // 
            this.panel7.Controls.Add(this.treeView1);
            this.panel7.Controls.Add(this.panel8);
            this.panel7.Dock = System.Windows.Forms.DockStyle.Fill;
            this.panel7.Location = new System.Drawing.Point(318, 2);
            this.panel7.Name = "panel7";
            this.panel7.Size = new System.Drawing.Size(476, 538);
            this.panel7.TabIndex = 22;
            // 
            // treeView1
            // 
            this.treeView1.BackColor = System.Drawing.SystemColors.Info;
            this.treeView1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.treeView1.CheckBoxes = true;
            this.treeView1.ContextMenu = this.contextMenu2;
            this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.treeView1.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.treeView1.Location = new System.Drawing.Point(0, 22);
            this.treeView1.Name = "treeView1";
            this.treeView1.Size = new System.Drawing.Size(476, 516);
            this.treeView1.TabIndex = 18;
            this.treeView1.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterCheck);
            // 
            // contextMenu2
            // 
            this.contextMenu2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem8,
            this.menuItem9,
            this.menuItem3,
            this.menuItem4,
            this.menuItem10,
            this.menuItem11,
            this.menuItem12,
            this.menuItem13,
            this.menuItem14});
            // 
            // menuItem8
            // 
            this.menuItem8.Index = 0;
            this.menuItem8.Text = "Lưu phân quyền";
            this.menuItem8.Click += new System.EventHandler(this.butLuu_Click);
            // 
            // menuItem9
            // 
            this.menuItem9.Index = 1;
            this.menuItem9.Text = "-";
            // 
            // menuItem3
            // 
            this.menuItem3.Index = 2;
            this.menuItem3.Text = "Copy quyền";
            this.menuItem3.Click += new System.EventHandler(this.butCopyts_Click);
            // 
            // menuItem4
            // 
            this.menuItem4.Enabled = false;
            this.menuItem4.Index = 3;
            this.menuItem4.Text = "Paste quyền";
            this.menuItem4.Click += new System.EventHandler(this.butPastets_Click);
            // 
            // menuItem10
            // 
            this.menuItem10.Index = 4;
            this.menuItem10.Text = "-";
            // 
            // menuItem11
            // 
            this.menuItem11.Index = 5;
            this.menuItem11.Text = "Chọn tất cả";
            this.menuItem11.Click += new System.EventHandler(this.butAll_Click);
            // 
            // menuItem12
            // 
            this.menuItem12.Index = 6;
            this.menuItem12.Text = "-";
            // 
            // menuItem13
            // 
            this.menuItem13.Index = 7;
            this.menuItem13.Text = "Mở rông tất cả các nút";
            this.menuItem13.Click += new System.EventHandler(this.menuItem13_Click);
            // 
            // menuItem14
            // 
            this.menuItem14.Index = 8;
            this.menuItem14.Text = "Đóng tất cả các nút";
            this.menuItem14.Click += new System.EventHandler(this.menuItem14_Click);
            // 
            // panel8
            // 
            this.panel8.Controls.Add(this.txtNodeTextSearch);
            this.panel8.Controls.Add(this.butPastets);
            this.panel8.Controls.Add(this.label3);
            this.panel8.Controls.Add(this.butCopyts);
            this.panel8.Controls.Add(this.label1);
            this.panel8.Dock = System.Windows.Forms.DockStyle.Top;
            this.panel8.Location = new System.Drawing.Point(0, 0);
            this.panel8.Name = "panel8";
            this.panel8.Size = new System.Drawing.Size(476, 22);
            this.panel8.TabIndex = 1;
            // 
            // txtNodeTextSearch
            // 
            this.txtNodeTextSearch.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtNodeTextSearch.BackColor = System.Drawing.SystemColors.HighlightText;
            this.txtNodeTextSearch.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtNodeTextSearch.ForeColor = System.Drawing.Color.Red;
            this.txtNodeTextSearch.Location = new System.Drawing.Point(175, 0);
            this.txtNodeTextSearch.Name = "txtNodeTextSearch";
            this.txtNodeTextSearch.Size = new System.Drawing.Size(130, 21);
            this.txtNodeTextSearch.TabIndex = 22;
            this.txtNodeTextSearch.Text = "Tìm kiếm";
            this.txtNodeTextSearch.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtNodeTextSearch.TextChanged += new System.EventHandler(this.txtNodeTextSearch_TextChanged);
            this.txtNodeTextSearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtNodeTextSearch_KeyDown);
            this.txtNodeTextSearch.Enter += new System.EventHandler(this.txtNodeTextSearch_Enter);
            // 
            // butPastets
            // 
            this.butPastets.Cursor = System.Windows.Forms.Cursors.Hand;
            this.butPastets.Dock = System.Windows.Forms.DockStyle.Left;
            this.butPastets.Enabled = false;
            this.butPastets.Image = ((System.Drawing.Image)(resources.GetObject("butPastets.Image")));
            this.butPastets.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butPastets.Location = new System.Drawing.Point(90, 0);
            this.butPastets.Name = "butPastets";
            this.butPastets.Size = new System.Drawing.Size(85, 22);
            this.butPastets.TabIndex = 21;
            this.butPastets.Text = "Paste quyền";
            this.butPastets.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butPastets.Click += new System.EventHandler(this.butPastets_Click);
            // 
            // label3
            // 
            this.label3.Dock = System.Windows.Forms.DockStyle.Left;
            this.label3.Location = new System.Drawing.Point(85, 0);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(5, 22);
            this.label3.TabIndex = 20;
            // 
            // butCopyts
            // 
            this.butCopyts.Cursor = System.Windows.Forms.Cursors.Hand;
            this.butCopyts.Dock = System.Windows.Forms.DockStyle.Left;
            this.butCopyts.Image = ((System.Drawing.Image)(resources.GetObject("butCopyts.Image")));
            this.butCopyts.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butCopyts.Location = new System.Drawing.Point(5, 0);
            this.butCopyts.Name = "butCopyts";
            this.butCopyts.Size = new System.Drawing.Size(80, 22);
            this.butCopyts.TabIndex = 19;
            this.butCopyts.Text = "Copy quyền";
            this.butCopyts.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butCopyts.Click += new System.EventHandler(this.butCopyts_Click);
            // 
            // label1
            // 
            this.label1.Dock = System.Windows.Forms.DockStyle.Left;
            this.label1.Location = new System.Drawing.Point(0, 0);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(5, 22);
            this.label1.TabIndex = 18;
            // 
            // frmRight
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(794, 572);
            this.Controls.Add(this.panel7);
            this.Controls.Add(this.panel6);
            this.Controls.Add(this.splitter1);
            this.Controls.Add(this.panel4);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.txtRight);
            this.Controls.Add(this.txtUserId);
            this.Controls.Add(this.panel2);
            this.Controls.Add(this.panel3);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "frmRight";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Phân quyền sử dụng";
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.Load += new System.EventHandler(this.frmRight_Load);
            this.panel4.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
            this.panel5.ResumeLayout(false);
            this.panel5.PerformLayout();
            this.panel6.ResumeLayout(false);
            this.panel7.ResumeLayout(false);
            this.panel8.ResumeLayout(false);
            this.panel8.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		private void AddGridTableStyle()
		{
			dataGrid1.TableStyles.Clear();
			DataGridTableStyle ts =new DataGridTableStyle();
			ts.MappingName = ds.Tables[0].TableName;
			ts.RowHeadersVisible=false;
			ts.ColumnHeadersVisible=false;
			ts.GridLineColor= Color.White;
			//0
			DataGridIconColumn  iconColumn = new DataGridIconColumn(this.imgList,new delegateGetIconIndexForRow(MyGetImageIndexForRow));
			iconColumn.HeaderText = "";
			iconColumn.MappingName = "Icon";
			iconColumn.Width = this.imgList.Images[0].Size.Width;
			ts.GridColumnStyles.Add(iconColumn);
			dataGrid1.TableStyles.Add(ts);
			//1
			DataGridTextBoxColumn TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "userid";
			TextCol1.HeaderText = "User ID"; 
			TextCol1.Width = 100;
			ts.GridColumnStyles.Add(TextCol1);
			dataGrid1.TableStyles.Add(ts);		
			//2
			TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "password_";
			TextCol1.HeaderText = "";
			TextCol1.Width = 0;
			ts.GridColumnStyles.Add(TextCol1);
			dataGrid1.TableStyles.Add(ts);	
			//3
			TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "right_";
			TextCol1.HeaderText = "";
			TextCol1.Width = 0;
			ts.GridColumnStyles.Add(TextCol1);
			dataGrid1.TableStyles.Add(ts);	
			//4
			TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "chuong";
			TextCol1.HeaderText = "";
			TextCol1.Width = 0;
			ts.GridColumnStyles.Add(TextCol1);
			dataGrid1.TableStyles.Add(ts);	
			//5
			TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "lk";
			TextCol1.HeaderText = "";
			TextCol1.Width = 0;
			ts.GridColumnStyles.Add(TextCol1);
			dataGrid1.TableStyles.Add(ts);	
			//6
			TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "chucnang";
			TextCol1.HeaderText = "";
			TextCol1.Width = 0;
			ts.GridColumnStyles.Add(TextCol1);
			dataGrid1.TableStyles.Add(ts);	
			//7
			TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "lctug";
			TextCol1.HeaderText = "";
			TextCol1.Width = 0;
			ts.GridColumnStyles.Add(TextCol1);
			dataGrid1.TableStyles.Add(ts);	
			//8
			TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "nghiepvu";
			TextCol1.HeaderText = "";
			TextCol1.Width = 0;
			ts.GridColumnStyles.Add(TextCol1);
			dataGrid1.TableStyles.Add(ts);	
			//9
			TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "admin";
			TextCol1.HeaderText = "";
			TextCol1.Width = 0;
			ts.GridColumnStyles.Add(TextCol1);
			dataGrid1.TableStyles.Add(ts);	
			//10
			TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "hoten";
			TextCol1.HeaderText = "";
			TextCol1.Width=150;
			ts.GridColumnStyles.Add(TextCol1);
			dataGrid1.TableStyles.Add(ts);	
			//11
			TextCol1=new DataGridTextBoxColumn();
			TextCol1.MappingName = "id";
			TextCol1.HeaderText = "";
			TextCol1.Width=0;
			ts.GridColumnStyles.Add(TextCol1);
			dataGrid1.TableStyles.Add(ts);	
		}

		public delegate int delegateGetIconIndexForRow(int row);
		public class DataGridIconColumn : DataGridTextBoxColumn
		{
			private ImageList _icons;
			delegateGetIconIndexForRow _getIconIndex;
		
			public DataGridIconColumn(ImageList Icons, delegateGetIconIndexForRow getIconIndex)
			{
				_icons = Icons;
				_getIconIndex = getIconIndex;
			}

			protected override void Edit(System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible) 
			{ 
				if(this.MappingName == "Icon") return; 
 				base.Edit(source, rowNum, bounds, readOnly, instantText, cellIsVisible); 
			} 

			protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
			{
				try
				{
					g.FillRectangle(backBrush, bounds);
					g.DrawImage(this._icons.Images[_getIconIndex(rowNum)], bounds);
				}	
				catch{}
			}
		}

		public int MyGetImageIndexForRow(int row)
		{	
			return row % 3;
		}

		private void frmRight_Load(object sender, System.EventArgs e)
		{
			try
			{
				ads_Menu = d.get_data("select * from a_menuitem order by id");
				int i = int.Parse(ads_Menu.Tables[0].Rows[0][0].ToString());
			}
			catch
			{
				d.execute_data(" create table a_menuitem(id varchar2(5),id_goc varchar2(5),stt number(5) default 0,id_menu varchar2(5),ten nvarchar2(500)  ,constraint pk_a_menuitem primary key(id))");
				ads_Menu = d.get_data("select * from a_menuitem order by id");
			}
			if(ads_Menu.Tables[0].Rows.Count>0 )
			{
				f_Load_Tree();
			}

			ds=d.get_data("select * from a_dlogin order by hoten");
			ds.Tables[0].Columns.Add("Icon");
			AddGridTableStyle();
			dataGrid1.DataSource=ds.Tables[0];
			ref_text();
		}

		private void butKethuc_Click(object sender, System.EventArgs e)
		{
			d.close();System.GC.Collect();this.Close();
		}		
	

		private void luu_right()
		{
			try
			{
				d.upd_a_dlogin(int.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,11].ToString()),strRight);
				d.updrec(ds.Tables[0],int.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,11].ToString()),"","","",strRight);

			}
			catch{}
		}

		private void butThem_Click(object sender, System.EventArgs e)
		{
			frmUser f=new frmUser(d,ds,"","","","",true);
			f.ShowDialog();
			ds=f.dsright;
		}

		private void butSua_Click(object sender, System.EventArgs e)
		{
			frmUser f=new frmUser(d,ds,dataGrid1[dataGrid1.CurrentCell.RowNumber,11].ToString(),txtUserId.Text,dataGrid1[dataGrid1.CurrentCell.RowNumber,2].ToString(),dataGrid1[dataGrid1.CurrentCell.RowNumber,3].ToString(),true);
			f.ShowDialog();	
			ds=f.dsright;
		}

		private void butHuy_Click(object sender, System.EventArgs e)
		{
			if (ds.Tables[0].Rows.Count==1)
			{
				MessageBox.Show("Không được hủy !",d.Msg);
				return;
			}
			if (MessageBox.Show("Đồng ý hủy ?",d.Msg,MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
			{
				int tableid=d.tableid("","a_dlogin");
				d.upd_eve_tables(tableid,i_userid,"del");
				d.upd_eve_upd_del(tableid,i_userid,"del",d.fields("a_dlogin","id="+long.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,11].ToString())));
				d.execute_data("delete from a_dlogin where id="+long.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,11].ToString()));
				d.delrec(ds.Tables[0],"id="+long.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,11].ToString()));
				ds.AcceptChanges();
			}
		}

		private void butAll_Click(object sender, System.EventArgs e)
		{
			butAll.Text = butAll.Text == "Chọn cả" ? "Bỏ cả" : "Chọn cả";
			menuItem11.Text=menuItem11.Text== "Chọn cả" ? "Bỏ cả" : "Chọn cả";

			if (butAll.Text == "Chọn cả") f_Set_All(false);
			else f_Set_All(true);
		}

		private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
		{
			ref_text();
		}

		private void ref_text()
		{
			try
			{				
				txtRight.Text=dataGrid1[dataGrid1.CurrentCell.RowNumber,3].ToString();
				txtUserId.Text=dataGrid1[dataGrid1.CurrentCell.RowNumber,1].ToString();
				f_Set_Right();
			}
			catch{}
		}

		private void menuItem14_Click(object sender, System.EventArgs e)
		{
			treeView1.CollapseAll();
		}

		private void menuItem13_Click(object sender, System.EventArgs e)
		{
			treeView1.ExpandAll();
		}

		private void tim_Enter(object sender, System.EventArgs e)
		{
			txtTimUser.Text="";
		}

		private void tim_TextChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==txtTimUser)
			{
				CurrencyManager cm= (CurrencyManager)BindingContext[dataGrid1.DataSource];
				DataView dv=(DataView)cm.List;
				dv.RowFilter="hoten like '%"+txtTimUser.Text.Trim()+"%' or userid like '%"+txtTimUser.Text.Trim()+"%'";
				ref_text();
			}
		}

		private void butLuu_Click(object sender, System.EventArgs e)
		{
			strRight = "";
			f_Get_Right();
			luu_right();
			butThem.Focus();
		}
		private void f_Set_Right()
		{
			foreach (TreeNode anode in treeView1.Nodes)
			{
				if (anode.Nodes.Count > 0) f_Set_Right(anode);
				else
				{
					if (txtRight.Text.Trim().IndexOf(anode.Tag.ToString() + "+") != -1)
					{
						anode.Checked = true;
					}
					else anode.Checked = false;
				}
			}
		}
		private void f_Set_Right(TreeNode v_node)
		{

			try
			{
				foreach (TreeNode anode in v_node.Nodes)
				{
					if (anode.Nodes.Count > 0)
					{
						f_Set_Right(anode);
					}
					else
					{
						if (txtRight.Text.Trim().IndexOf(anode.Tag.ToString() + "+") != -1)
						{
							anode.Checked = true;
						}
						else anode.Checked = false;
					}
				}
			}
			catch
			{
			}
		}
		private void f_Get_Right()
		{
			foreach (TreeNode anode in treeView1.Nodes)
			{
				if (anode.Nodes.Count > 0)
				{
					f_Get_Right(anode);
				}
			}
		}
		private void f_Get_Right(TreeNode v_node)
		{
			try
			{
				foreach (TreeNode anode in v_node.Nodes)
				{
					if (anode.Nodes.Count > 0)
					{
						f_Get_Right(anode);
					}
					else
					{
						if (anode.Checked)
						{
							strRight += anode.Tag.ToString() + "+";
						}
					}
				}
			}
			catch
			{
			}
		}
		private void f_Set_All(bool bAll)
		{
			foreach (TreeNode anode in treeView1.Nodes)
			{
				if (anode.Nodes.Count > 0)
				{
					f_Chon_Quyen(anode, bAll);
				}
			}
		}
		private void f_Chon_Quyen(TreeNode v_node, bool v_bool)
		{
			try
			{
				foreach (TreeNode anode in v_node.Nodes)
				{
					anode.Checked = v_bool;
					if (anode.Nodes.Count > 0)
					{
						f_Chon_Quyen(anode, v_bool);
					}
				}
			}
			catch
			{
			}
		}

		private void treeView1_AfterCheck(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			try
			{
				if (e.Action == TreeViewAction.ByMouse || e.Action == TreeViewAction.ByKeyboard)
				{
					f_Chon_Quyen(e.Node, e.Node.Checked);
				}
			}
			catch
			{
			}
		}
		private void f_Load_Tree()
		{
			try
			{
				adsRight = d.get_data("select * from " + d.user + ".a_menuitem");
			}
			catch
			{

			}
			treeView1.Nodes.Clear();
			TreeNode anode, anode1;
			anode1 = new TreeNode("Chức năng");
			anode1.Tag = "menuChucnang";
			anode1.Text = "Chức năng";
			treeView1.Nodes.Add(anode1);
			foreach (DataRow r in adsRight.Tables[0].Select("id_goc='-1'", "id"))
			{
				anode = new TreeNode(r["ten"].ToString());
				anode.Tag = r["id_menu"].ToString().Trim();
				anode.ForeColor = Color.Black;
				if (adsRight.Tables[0].Select("id_goc=" + anode.Tag.ToString(), "stt").Length > 0)
				{
					f_Add_Node(anode);
				}
				anode1.Nodes.Add(anode);
			}
	
			treeView1.ExpandAll();
			treeView1.SelectedNode = anode1;
		}
		private void f_Add_Node(TreeNode v_node)
		{
			try
			{
				TreeNode anode;
				foreach (DataRow r in adsRight.Tables[0].Select("id_goc=" + v_node.Tag.ToString(), "stt"))
				{
					anode = new TreeNode(r["ten"].ToString());
					anode.Tag = r["id_menu"].ToString().Trim();
					anode.ForeColor = Color.Black;
					if (adsRight.Tables[0].Select("id_goc=" + anode.Tag.ToString(), "stt").Length > 0)
					{
						f_Add_Node(anode);
					}
					v_node.Nodes.Add(anode);
				}
			}
			catch
			{
			}
		}

		private void butCopyts_Click(object sender, EventArgs e)
		{
			f_Copy();
		}
		private void f_Copy()
		{
			try
			{
				string aid = "";
				try
				{
					aid = txtRight.Text.Trim();
				}
				catch
				{
					aid = "";
				}
				m_id_copy = aid;
			}
			catch
			{
			}
			finally
			{
				butPastets.Enabled = m_id_copy != "";
				menuItem2.Enabled = m_id_copy != "";
				menuItem4.Enabled = m_id_copy != "";
			}
		}

		private void butPastets_Click(object sender, EventArgs e)
		{
			f_Paste();
		}
		private void f_Paste()
		{
			try
			{
				string aid = "", auserid = "";
				try
				{
					aid = txtRight.Text;
					auserid = dataGrid1[dataGrid1.CurrentCell.RowNumber, 11].ToString();
				}
				catch
				{
					aid = "";
				}
				if (m_id_copy != "" && auserid != "")
				{
					if (MessageBox.Show(this,"Đồng ý paste quyền cho đối tượng đang chọn!", d.Msg, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
					{
						d.execute_data("update a_dlogin set right_='" + m_id_copy + "' where id=" + auserid + "");
						ref_text(m_id_copy);
					}
				}
			}
			catch
			{
			}
		}
		private void ref_text(string quyen)
		{
			try
			{
				txtRight.Text = quyen;
				f_Set_Right();
			}
			catch { }
		}
		private void txtNodeTextSearch_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Tab || e.KeyCode == Keys.Enter) treeView1.Focus();
		}

		private void txtNodeTextSearch_Enter(object sender, System.EventArgs e)
		{
			txtNodeTextSearch.Text = "";
		}
		private void NodeTextSearch()
		{
			ClearBackColor();
			FindByText();
		}
		private void ClearBackColor()
		{
			TreeNodeCollection nodes = treeView1.Nodes;
			foreach (TreeNode n in nodes)
			{
				ClearRecursive(n);
			}
		}
		private void FindByText()
		{
			TreeNodeCollection nodes = treeView1.Nodes;
			foreach (TreeNode n in nodes)
			{
				FindRecursive(n);
			}
		}
		private void FindRecursive(TreeNode treeNode)
		{
			foreach (TreeNode tn in treeNode.Nodes)
			{
				if (tn.Text.ToLower().IndexOf(this.txtNodeTextSearch.Text.ToLower().Trim())!=-1)
					tn.BackColor = Color.Yellow;
				FindRecursive(tn);
			}
		}
		private void ClearRecursive(TreeNode treeNode)
		{
			foreach (TreeNode tn in treeNode.Nodes)
			{
				tn.BackColor = Color.White;
				ClearRecursive(tn);
			}
		}

		private void txtNodeTextSearch_TextChanged(object sender, System.EventArgs e)
		{
			NodeTextSearch();
		}

	}
}
